// Copyright (c) 2024，D-Robotics.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/***************************************************************************
 *                      COPYRIGHT NOTICE
 *             Copyright(C) 2024, D-Robotics Co., Ltd.
 *                     All rights reserved.
 ***************************************************************************/

#ifndef __HBN_ERROR_H__
#define __HBN_ERROR_H__

#ifdef __cplusplus
extern "C" {
#endif

#define HBN_STATUS_SUCESS (0)
#define HBN_STATUS_INVALID_NODE (1)
#define HBN_STATUS_INVALID_NODETYPE (2)
#define HBN_STATUS_INVALID_HWID (3)
#define HBN_STATUS_INVALID_CTXID (4)
#define HBN_STATUS_INVALID_OCHNID (5)
#define HBN_STATUS_INVALID_ICHNID (6)
#define HBN_STATUS_INVALID_FORMAT (7)
#define HBN_STATUS_INVALID_NULL_PTR (8)
#define HBN_STATUS_INVALID_PARAMETER (9)
#define HBN_STATUS_ILLEGAL_ATTR (10)
#define HBN_STATUS_INVALID_FLOW (11)
#define HBN_STATUS_FLOW_EXIST (12)
#define HBN_STATUS_FLOW_UNEXIST (13)
#define HBN_STATUS_NODE_EXIST (14)
#define HBN_STATUS_NODE_UNEXIST (15)
#define HBN_STATUS_NOT_CONFIG (16)
#define HBN_STATUS_CHN_NOT_ENABLED (17)
#define HBN_STATUS_CHN_ALREADY_ENABLED (18)
#define HBN_STATUS_ALREADY_BINDED (19)
#define HBN_STATUS_NOT_BINDED (20)
#define HBN_STATUS_TIMEOUT (21)
#define HBN_STATUS_NOT_INITIALIZED (22)
#define HBN_STATUS_NOT_SUPPORT (23)
#define HBN_STATUS_NOT_PERM (24)
#define HBN_STATUS_NOMEM (25)
#define HBN_STATUS_INVALID_VNODE_FD (26)
#define HBN_STATUS_INVALID_ICHNID_FD (27)
#define HBN_STATUS_INVALID_OCHNID_FD (28)
#define HBN_STATUS_OPEN_OCHN_FAIL (29)
#define HBN_STATUS_OPEN_ICHN_FAIL (30)
#define HBN_STATUS_JSON_PARSE_FAIL (31)
#define HBN_STATUS_REQ_BUF_FAIL (32)
#define HBN_STATUS_QUERY_BUF_FAIL (33)
#define HBN_STATUS_SET_CONTROL_FAIL (34)
#define HBN_STATUS_GET_CONTROL_FAIL (35)
#define HBN_STATUS_NODE_START_FAIL (36)
#define HBN_STATUS_NODE_STOP_FAIL (37)
#define HBN_STATUS_NODE_POLL_ERROR (38)
#define HBN_STATUS_NODE_POLL_TIMEOUT (39)
#define HBN_STATUS_NODE_POLL_FRAME_DROP (40)
#define HBN_STATUS_NODE_POLL_HUP (41)
#define HBN_STATUS_NODE_ILLEGAL_EVENT (42)
#define HBN_STATUS_NODE_DEQUE_ERROR (43)
#define HBN_STATUS_ILLEGAL_BUF_INDEX (44)
#define HBN_STATUS_NODE_QUE_ERROR (45)
#define HBN_STATUS_FLUSH_FRAME_ERROR (46)
#define HBN_STATUS_INIT_BIND_ERROR (47)
#define HBN_STATUS_ADD_NODE_FAIL (48)
#define HBN_STATUS_WRONG_CONFIG_ID (49)
#define HBN_STATUS_BIND_NODE_FAIL (50)
#define HBN_STATUS_INVALID_VERSION (51)
#define HBN_STATUS_GET_VERSION_ERROR (52)
#define HBN_STATUS_MEM_INIT_FAIL (53)
#define HBN_STATUS_MEM_IMPORT_FAIL (54)
#define HBN_STATUS_MEM_FREE_FAIL (55)
#define HBN_STATUS_SYSFS_OPEN_FAIL (56)
#define HBN_STATUS_STRUCT_SIZE_NOT_MATCH (57)
#define HBN_STATUS_RGN_UNEXIST (58)
#define HBN_STATUS_RGN_INVALID_OPERATION (59)
#define HBN_STATUS_RGN_OPEN_FILE_FAIL (60)

#define HBN_STATUS_ERR_UNKNOW (128)

#define COMBINE_ERRCODE(module_id, err_info) ((module_id << 16) | (err_info & 0xFFFF))

// vin module common error
#define HBN_STATUS_VIN_INVALID_NODE COMBINE_ERRCODE(HB_VIN, HBN_STATUS_INVALID_NODE) //0xB0001
#define HBN_STATUS_VIN_INVALID_NODETYPE COMBINE_ERRCODE(HB_VIN, HBN_STATUS_INVALID_NODETYPE) //0xB0002
#define HBN_STATUS_VIN_INVALID_HWID COMBINE_ERRCODE(HB_VIN, HBN_STATUS_INVALID_HWID) //0xB0003
#define HBN_STATUS_VIN_INVALID_CTXID COMBINE_ERRCODE(HB_VIN, HBN_STATUS_INVALID_CTXID) //0xB0004
#define HBN_STATUS_VIN_INVALID_OCHNID COMBINE_ERRCODE(HB_VIN, HBN_STATUS_INVALID_OCHNID) //0xB0005
#define HBN_STATUS_VIN_INVALID_ICHNID COMBINE_ERRCODE(HB_VIN, HBN_STATUS_INVALID_ICHNID) //0xB0006
#define HBN_STATUS_VIN_INVALID_FORMAT COMBINE_ERRCODE(HB_VIN, HBN_STATUS_INVALID_FORMAT) //0xB0007
#define HBN_STATUS_VIN_INVALID_NULL_PTR COMBINE_ERRCODE(HB_VIN, HBN_STATUS_INVALID_NULL_PTR) //0xB0008
#define HBN_STATUS_VIN_INVALID_PARAMETER COMBINE_ERRCODE(HB_VIN, HBN_STATUS_INVALID_PARAMETER) //0xB0009
#define HBN_STATUS_VIN_ILLEGAL_ATTR COMBINE_ERRCODE(HB_VIN, HBN_STATUS_ILLEGAL_ATTR) //0xB000A
#define HBN_STATUS_VIN_INVALID_FLOW COMBINE_ERRCODE(HB_VIN, HBN_STATUS_INVALID_FLOW) //0xB000B
#define HBN_STATUS_VIN_FLOW_EXIST COMBINE_ERRCODE(HB_VIN, HBN_STATUS_FLOW_EXIST) //0xB000C
#define HBN_STATUS_VIN_FLOW_UNEXIST COMBINE_ERRCODE(HB_VIN, HBN_STATUS_FLOW_UNEXIST) //0xB000D
#define HBN_STATUS_VIN_NODE_EXIST COMBINE_ERRCODE(HB_VIN, HBN_STATUS_NODE_EXIST) //0xB000E
#define HBN_STATUS_VIN_NODE_UNEXIST COMBINE_ERRCODE(HB_VIN, HBN_STATUS_NODE_UNEXIST) //0xB000F
#define HBN_STATUS_VIN_NOT_CONFIG COMBINE_ERRCODE(HB_VIN, HBN_STATUS_NOT_CONFIG) //0xB0010
#define HBN_STATUS_VIN_CHN_NOT_ENABLED COMBINE_ERRCODE(HB_VIN, HBN_STATUS_CHN_NOT_ENABLED) //0xB0011
#define HBN_STATUS_VIN_CHN_ALREADY_ENABLED COMBINE_ERRCODE(HB_VIN, HBN_STATUS_CHN_ALREADY_ENABLED) //0xB0012
#define HBN_STATUS_VIN_ALREADY_BINDED COMBINE_ERRCODE(HB_VIN, HBN_STATUS_ALREADY_BINDED) //0xB0013
#define HBN_STATUS_VIN_NOT_BINDED COMBINE_ERRCODE(HB_VIN, HBN_STATUS_NOT_BINDED) //0xB0014
#define HBN_STATUS_VIN_TIMEOUT COMBINE_ERRCODE(HB_VIN, HBN_STATUS_TIMEOUT) //0xB0015
#define HBN_STATUS_VIN_NOT_INITIALIZED COMBINE_ERRCODE(HB_VIN, HBN_STATUS_NOT_INITIALIZED) //0xB0016
#define HBN_STATUS_VIN_NOT_SUPPORT COMBINE_ERRCODE(HB_VIN, HBN_STATUS_NOT_SUPPORT) //0xB0017
#define HBN_STATUS_VIN_NOT_PERM COMBINE_ERRCODE(HB_VIN, HBN_STATUS_NOT_PERM) //0xB0018
#define HBN_STATUS_VIN_NOMEM COMBINE_ERRCODE(HB_VIN, HBN_STATUS_NOMEM) //0xB0019
#define HBN_STATUS_VIN_INVALID_VNODE_FD COMBINE_ERRCODE(HB_VIN, HBN_STATUS_INVALID_VNODE_FD) //0xB002A
#define HBN_STATUS_VIN_INVALID_ICHNID_FD COMBINE_ERRCODE(HB_VIN, HBN_STATUS_INVALID_ICHNID_FD) //0xB002B
#define HBN_STATUS_VIN_INVALID_OCHNID_FD COMBINE_ERRCODE(HB_VIN, HBN_STATUS_INVALID_OCHNID_FD) //0xB002C
#define HBN_STATUS_VIN_OPEN_OCHN_FAIL COMBINE_ERRCODE(HB_VIN, HBN_STATUS_OPEN_OCHN_FAIL) //0xB002D
#define HBN_STATUS_VIN_OPEN_ICHN_FAIL COMBINE_ERRCODE(HB_VIN, HBN_STATUS_OPEN_ICHN_FAIL) //0xB002E
#define HBN_STATUS_VIN_JSON_PARSE_FAIL COMBINE_ERRCODE(HB_VIN, HBN_STATUS_JSON_PARSE_FAIL) //0xB002F

// vin module special error

//gdc module common error

#define HBN_STATUS_GDC_INVALID_PARAMETER COMBINE_ERRCODE(HB_GDC, HBN_STATUS_INVALID_PARAMETER) //0x50009
#define HBN_STATUS_GDC_NODE_UNEXIST COMBINE_ERRCODE(HB_GDC, HBN_STATUS_NODE_UNEXIST) //0x5000f
#define HBN_STATUS_GDC_BIND_NODE_FAIL COMBINE_ERRCODE(HB_GDC, HBN_STATUS_BIND_NODE_FAIL) //0x50032
#define HBN_STATUS_GDC_INVALID_VERSION COMBINE_ERRCODE(HB_GDC, HBN_STATUS_INVALID_VERSION) //0x50033

//gdc module special error
#define HBN_STATUS_GEN_CFG_FAIL (129)
#define HBN_STATUS_GDC_GEN_CFG_FAIL COMBINE_ERRCODE(HB_GDC, HBN_STATUS_GEN_CFG_FAIL) //0x50081

//ISP module common error
#define HBN_STATUS_ISP_INVALID_NULL_PTR COMBINE_ERRCODE(HB_ISP, HBN_STATUS_INVALID_NULL_PTR) //0x0C0008
#define HBN_STATUS_ISP_INVALID_PARAMETER COMBINE_ERRCODE(HB_ISP, HBN_STATUS_INVALID_PARAMETER) //0x0C0009
#define HBN_STATUS_ISP_ILLEGAL_ATTR COMBINE_ERRCODE(HB_ISP, HBN_STATUS_ILLEGAL_ATTR) //0x0C000A
#define HBN_STATUS_ISP_NODE_UNEXIST COMBINE_ERRCODE(HB_ISP, HBN_STATUS_NODE_UNEXIST) //0x0C000f
#define HBN_STATUS_ISP_SET_CONTROL_FAIL COMBINE_ERRCODE(HB_ISP, HBN_STATUS_SET_CONTROL_FAIL) //0x0C0022
#define HBN_STATUS_ISP_GET_CONTROL_FAIL COMBINE_ERRCODE(HB_ISP, HBN_STATUS_GET_CONTROL_FAIL) //0x0C0023
#define HBN_STATUS_ISP_BIND_NODE_FAIL COMBINE_ERRCODE(HB_ISP, HBN_STATUS_BIND_NODE_FAIL) //0x0C0032
#define HBN_STATUS_ISP_INVALID_VERSION COMBINE_ERRCODE(HB_ISP, HBN_STATUS_INVALID_VERSION) //0x0C0033
#define HBN_STATUS_ISP_MEM_INIT_FAIL COMBINE_ERRCODE(HB_ISP, HBN_STATUS_MEM_INIT_FAIL) //0x0C0035
#define HBN_STATUS_ISP_MEM_IMPORT_FAIL COMBINE_ERRCODE(HB_ISP, HBN_STATUS_MEM_IMPORT_FAIL) //0x0C0036
#define HBN_STATUS_ISP_MEM_FREE_FAIL COMBINE_ERRCODE(HB_ISP, HBN_STATUS_MEM_FREE_FAIL) //0x0C0037
#define HBN_STATUS_ISP_SYSFS_OPEN_FAIL COMBINE_ERRCODE(HB_ISP, HBN_STATUS_SYSFS_OPEN_FAIL) //0x0C0038
#define HBN_STATUS_ISP_2A_ERROR COMBINE_ERRCODE(HB_ISP, HBN_STATUS_ERR_UNKNOW) //0x0C0080
#define HBN_STATUS_ISP_OPEN_ICHN_FAIL COMBINE_ERRCODE(HB_ISP, HBN_STATUS_OPEN_ICHN_FAIL)
#define HBN_STATUS_ISP_OPEN_OCHN_FAIL COMBINE_ERRCODE(HB_ISP, HBN_STATUS_OPEN_OCHN_FAIL)
#define HBN_STATUS_ISP_INVALID_NODE COMBINE_ERRCODE(HB_ISP, HBN_STATUS_INVALID_NODE) //0xB0001
#define HBN_STATUS_ISP_INVALID_NODETYPE COMBINE_ERRCODE(HB_ISP, HBN_STATUS_INVALID_NODETYPE) //0xB0002

// vse module common error
#define HBN_STATUS_VSE_JSON_PARSE_FAIL COMBINE_ERRCODE(HB_VSE, HBN_STATUS_JSON_PARSE_FAIL)
#define HBN_STATUS_VSE_ILLEGAL_ATTR COMBINE_ERRCODE(HB_VSE, HBN_STATUS_ILLEGAL_ATTR)
#define HBN_STATUS_VSE_INVALID_NULL_PTR COMBINE_ERRCODE(HB_VSE, HBN_STATUS_INVALID_NULL_PTR)
#define HBN_STATUS_VSE_OPEN_ICHN_FAIL COMBINE_ERRCODE(HB_VSE, HBN_STATUS_OPEN_ICHN_FAIL)
#define HBN_STATUS_VSE_OPEN_OCHN_FAIL COMBINE_ERRCODE(HB_VSE, HBN_STATUS_OPEN_OCHN_FAIL)
#define HBN_STATUS_VSE_INVALID_PARAMETER COMBINE_ERRCODE(HB_VSE, HBN_STATUS_INVALID_PARAMETER)

// osd module common error
#define HBN_STATUS_OSD_NOMEM COMBINE_ERRCODE(HB_OSD, HBN_STATUS_NOMEM)
#define HBN_STATUS_OSD_UNEXIST COMBINE_ERRCODE(HB_OSD, HBN_STATUS_RGN_UNEXIST)
#define HBN_STATUS_OSD_INVALID_OPERATION COMBINE_ERRCODE(HB_OSD, HBN_STATUS_RGN_INVALID_OPERATION)
#define HBN_STATUS_OSD_OPEN_FILE_FAIL COMBINE_ERRCODE(HB_OSD, HBN_STATUS_RGN_OPEN_FILE_FAIL)
#define HBN_STATUS_OSD_INVALID_NULL_PTR COMBINE_ERRCODE(HB_OSD, HBN_STATUS_INVALID_NULL_PTR)
#define HBN_STATUS_OSD_ILLEGAL_ATTR COMBINE_ERRCODE(HB_OSD, HBN_STATUS_ILLEGAL_ATTR)
#define HBN_STATUS_OSD_INVALID_PARAMETER COMBINE_ERRCODE(HB_OSD, HBN_STATUS_INVALID_PARAMETER)

//sth module common error
#define HBN_STATUS_STH_OPEN_ICHN_FAIL COMBINE_ERRCODE(HB_STITCH, HBN_STATUS_OPEN_ICHN_FAIL) //0x09001E
#define HBN_STATUS_STH_OPEN_OCHN_FAIL COMBINE_ERRCODE(HB_STITCH, HBN_STATUS_OPEN_OCHN_FAIL) //0x09001D
#define HBN_STATUS_STH_INVALID_NULL_PTR COMBINE_ERRCODE(HB_STITCH, HBN_STATUS_INVALID_NULL_PTR) //0x090008
#define HBN_STATUS_STH_INVALID_PARAMETER COMBINE_ERRCODE(HB_STITCH, HBN_STATUS_INVALID_PARAMETER) //0x090009
#define HBN_STATUS_STH_JSON_PARSE_FAIL COMBINE_ERRCODE(HB_STITCH, HBN_STATUS_JSON_PARSE_FAIL) //0x09001F
#define HBN_STATUS_STH_INIT_BIND_ERROR COMBINE_ERRCODE(HB_STITCH, HBN_STATUS_INIT_BIND_ERROR) //0x09002F
#define HBN_STATUS_STH_INVALID_VERSION COMBINE_ERRCODE(HB_STITCH, HBN_STATUS_INVALID_VERSION) //0x090033

//n2d module common error
#define HBN_STATUS_N2D_INVALID_PARAMETER COMBINE_ERRCODE(HB_N2D, HBN_STATUS_INVALID_PARAMETER) //0x160009
#define HBN_STATUS_N2D_NODE_UNEXIST COMBINE_ERRCODE(HB_N2D, HBN_STATUS_NODE_UNEXIST) //0x16000f
#define HBN_STATUS_N2D_BIND_NODE_FAIL COMBINE_ERRCODE(HB_N2D, HBN_STATUS_BIND_NODE_FAIL) //0x160032
#define HBN_STATUS_N2D_INVALID_VERSION COMBINE_ERRCODE(HB_N2D, HBN_STATUS_INVALID_VERSION) //0x160033

const char *hbn_err_info(int32_t error_code);
const char *hbn_err_type(int32_t error_code);

#ifdef __cplusplus
}
#endif

#endif
